home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / AppsToGo / AppsToGo.src / DTS.Draw / PenSizeDialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  3.9 KB  |  155 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        PenSizeDialog.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.defs.h"        /* Get various application definitions.            */
  27. #include "App.protos.h"        /* Get the prototypes for the application.        */
  28.  
  29. #ifndef __TREEOBJ2__
  30. #include "TreeObj2.h"
  31. #endif
  32.  
  33.  
  34.  
  35. extern short    gPenHeight, gPenWidth, gCtlNum;
  36.  
  37.  
  38.  
  39. /*****************************************************************************/
  40. /*****************************************************************************/
  41.  
  42.  
  43.  
  44. /* Find out which tool was clicked or double-clicked on. */
  45.  
  46. #pragma segment PENS
  47. OSErr    PENSInitContent(FileRecHndl frHndl, WindowPtr window)
  48. {
  49.     OSErr            err;
  50.     TreeObjHndl        root, cobj;
  51.     ControlHandle    ctl;
  52.     TEHandle        te;
  53.     Handle            txt;
  54.     short            penHeight, penWidth, ph, pw, i;
  55.     Boolean            gotSize;
  56.     Str15            pstr;
  57.  
  58.     err = AddControlSet(window, (*frHndl)->fileState.sfType, kwStandardVis, 0, 0, nil);
  59.     if (err) return(err);
  60.  
  61.     penHeight = gPenHeight;        /* Assume that there are none selected. */
  62.     penWidth  = gPenWidth;
  63.     gotSize   = false;
  64.  
  65.     frHndl = GetNextDocument(window, kDocFileType);
  66.     root   = (*frHndl)->d.doc.root;
  67.     for (i = (*root)->numChildren; i;) {
  68.         cobj = GetChildHndl(root, --i);
  69.         if (DoTreeObjMethod(cobj, GETSELECTMESSAGE, 0)) {
  70.             if ((*cobj)->type < GROUPOBJ) {
  71.                 ph = mDerefCommon(cobj)->penHeight;
  72.                 pw = mDerefCommon(cobj)->penWidth;
  73.                 if (!gotSize) {
  74.                     gotSize = true;
  75.                     penHeight = ph;
  76.                     penWidth  = pw;
  77.                     continue;
  78.                 }
  79.                 if (penHeight != ph) penHeight = -1;
  80.                 if (penWidth  != pw) penWidth  = -1;
  81.             }
  82.         }
  83.     }
  84.  
  85.     pstr[0] = 0;
  86.     if (penHeight > -1)
  87.         pcpydec(pstr, penHeight);
  88.     txt = NewHandle(pstr[0]);
  89.     BlockMove(pstr + 1, *txt, pstr[0]);
  90.     CNum2Ctl(window, 100, &ctl);
  91.     te = (TEHandle)GetCRefCon(ctl);
  92.     UseControlStyle(ctl);
  93.     DisposeHandle(CTESwapText(te, txt, nil, true));
  94.     TESetSelect(0, 32767, te);
  95.  
  96.     pstr[0] = 0;
  97.     if (penWidth > -1)
  98.         pcpydec(pstr, penWidth);
  99.     txt = NewHandle(pstr[0]);
  100.     BlockMove(pstr + 1, *txt, pstr[0]);
  101.     CNum2Ctl(window, 101, &ctl);
  102.     te = (TEHandle)GetCRefCon(ctl);
  103.     DisposeHandle(CTESwapText(te, txt, nil, true));
  104.     TESetSelect(0, 32767, te);
  105.  
  106.     return(err);
  107. }
  108.  
  109.  
  110.  
  111. /*****************************************************************************/
  112.  
  113.  
  114.  
  115. #pragma segment PENS
  116. OSErr    PENSFreeWindow(FileRecHndl frHndl, WindowPtr window)
  117. {
  118.     ControlHandle    ctl;
  119.     TEHandle        te;
  120.     Str15            pstr;
  121.     short            i;
  122.     TreeObjHndl        root, cobj;
  123.     OSErr            err;
  124.  
  125.     if (gCtlNum == -1) {
  126.         CNum2Ctl(window, 100, &ctl);
  127.         te = (TEHandle)GetCRefCon(ctl);
  128.         BlockMove(*((*te)->hText), pstr + 1, (pstr[0] = (*te)->teLength));
  129.         gPenHeight = p2dec(pstr, nil);
  130.         CNum2Ctl(window, 101, &ctl);
  131.         te = (TEHandle)GetCRefCon(ctl);
  132.         BlockMove(*((*te)->hText), pstr + 1, (pstr[0] = (*te)->teLength));
  133.         gPenWidth = p2dec(pstr, nil);
  134.         frHndl = GetNextDocument(window, kDocFileType);
  135.         root   = (*frHndl)->d.doc.root;
  136.         for (i = (*root)->numChildren; i;) {
  137.             cobj = GetChildHndl(root, --i);
  138.             if (DoTreeObjMethod(cobj, GETSELECTMESSAGE, 0)) {
  139.                 if ((*cobj)->type < GROUPOBJ) {
  140.                     if (err = ModifyChild(PENSIZE_EDIT, root, i, false)) return(err);
  141.                     mDerefCommon(cobj)->penHeight = gPenHeight;
  142.                     mDerefCommon(cobj)->penWidth  = gPenWidth;
  143.                 }
  144.             }
  145.         }
  146.         HideWindow(window);
  147.         DoImageDocument(frHndl);
  148.     }
  149.  
  150.     return(noErr);
  151. }
  152.  
  153.  
  154.  
  155.